package com.tony.test;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class DbHelper extends SQLiteOpenHelper {
	private static DbHelper dbHelper;

	public DbHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

	}

	public static DbHelper getInstance(Context context) {
		if (dbHelper == null) {
			dbHelper = new DbHelper(context, "firewall.db", null, 1);
		}
		return dbHelper;
	}

	public void readMessage() {
		SQLiteDatabase db = dbHelper.getReadableDatabase();
		if (db != null) {
			Cursor cursor = db.rawQuery("select * from conversation order by time asc", null);
			if (cursor != null && cursor.getCount() > 0) {
				Log.d("lbingt", "conversation count is : " + cursor.getCount());

				cursor.close();
				cursor = null;
			}
		}
	}
}
